#include<iostream>
#include <stdexcept>
using namespace std;
class Time
{
protected:
	int hours,min,sec;
public:
	Time():hours(0),min(0),sec(0){}
	~Time(){}
	int getHour(){return hours;}
	int getMin(){return min;}
	int getSec(){return sec;}
};
class MilTime : public Time
{
private:
	int milhours,milsecond;
public:
	MilTime(int mh,int ms):Time(),milhours(0),milsecond(0)
	{
		setTime(mh,ms);
	}
	void setTime(int mh,int ms)
	{
		if (mh < 0 || mh > 2359 || ms < 0 || ms > 59) 
		{
            throw invalid_argument("输入的时间不合法");
        }
        milhours = mh;
        milsecond = ms;
        hours=mh/100;
        min=mh%100;
        if(min>60)
        {
        	throw invalid_argument("输入的时间不合法");
		}
        sec=ms;
        if (hours > 12) 
		{
            hours -= 12;
        }
		else if (hours == 12) 
		{
            hours = 0;
        }
	}
	int getHour(){return milhours;}
    int getStandHr(){return hours;}
};
int main()
{
	int mh,ms;
	cout << "请输入军用时间的小时和分钟:";
	cin >> mh;
	cout << "请输入军用时间的秒:";
	cin >> ms;
	try 
	{
        MilTime milTime(mh, ms);
        cout << "军用时间: " << milTime.getHour() << " hours " <<  milTime.getSec() << " seconds " << endl;
        cout << "标准时间: " << milTime.getStandHr() << ":" << milTime.getMin() << ":" << milTime.getSec();
        if (milTime.getHour() >= 1200) 
		{
            cout << " PM" << endl;
        } 
		else 
		{
            cout << " AM" << endl;
        }
    } 
	catch (const invalid_argument& e) 
	{
        cout <<  e.what() << endl;
    }
	return 0;
}